package com.leyou.order.controller;

import com.leyou.order.dto.OrderDTO;
import com.leyou.order.service.OrderService;
import com.leyou.order.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Auther: xiang
 * @Date: 2019/9/2 20:39
 * @Description:
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
   private OrderService orderService;

    /**
     * 创建订单
     * @param orderDTO
     * @return
     */
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody @Valid OrderDTO orderDTO){
        return ResponseEntity.status(HttpStatus.CREATED).body(orderService.createOrder(orderDTO));


    }

    /**
     * 根据订单Id返回订单数据
     * @param orderId
     * @return
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderVO> queryOrderById(@PathVariable("id") Long orderId){
        return ResponseEntity.ok(orderService.queryOrderById(orderId));
    }
    @GetMapping("url/{id}")
   public ResponseEntity<String> getPayUrl(@PathVariable("id") Long id){
        return ResponseEntity.ok(orderService.CreatePayUrl(id));


    }
     @GetMapping("/state/{id}")
    public ResponseEntity<Integer> queryOrderStatus(@PathVariable("id") Long orderId) {
        return ResponseEntity.ok(orderService.queryOrderStatus(orderId));
    }

}